/*
 * QSMSControl.cpp
 *
 *  Created on: 29.09.2009
 *      Author: Elena
 */

#include <QtGui/QMessageBox>
#include "QSMSControl.h"

QSMSControl::QSMSControl( mts_manager * mts_manager_)
			:mts_managerInstance( mts_manager_),
			 trItemLocal(NULL),
			 trItemLocalInbox(NULL),
			 trItemLocalOutbox(NULL),
			 trItemLocalDrafts(NULL),
			 trItemLocalTrash(NULL),
			 trItemSIM(NULL),
			 trItemSIMInbox(NULL),
			 trItemSIMOutbox(NULL),
			 trItemSIMDrafts(NULL),
			 trItemSIMTrash(NULL)
{
	mts_managerInstance->getLeftTree()->header()->hide();
	fillLeftTree();
}

QSMSControl& QSMSControl::getInstance( mts_manager * mts_manager_)
{
	static QSMSControl smsControl( mts_manager_ );
	return smsControl;
}

QSMSControl::~QSMSControl()
{
	// TODO Auto-generated destructor stub
}

void QSMSControl::fillLeftTree(){
	{{
	trItemLocal = new QTreeWidgetItem( mts_managerInstance->getLeftTree());
	trItemLocal->setText( 0, QObject::tr("Локальные") );

	QIcon itemIcon(":/mainWnd/img/picSMSLocal-grey.png");
	itemIcon.addPixmap(QPixmap(":/mainWnd/img/picSMSLocal.png"), QIcon::Active, QIcon::On);
	trItemLocal->setIcon(0, itemIcon);
	}}

	{{
	trItemLocalInbox = new QTreeWidgetItem( trItemLocal );
	trItemLocalInbox->setText( 0, QObject::tr("Входящие") );

	QIcon itemIcon(":/mainWnd/img/picSMSInbox.png");
	trItemLocalInbox->setIcon(0, itemIcon);
	}}

	{{
	trItemLocalOutbox = new QTreeWidgetItem( trItemLocal );
	trItemLocalOutbox->setText( 0, QObject::tr("Исходящие") );

	QIcon itemIcon(":/mainWnd/img/picSMSOutbox.png");
	trItemLocalOutbox->setIcon(0, itemIcon);
	}}

	{{
	trItemLocalDrafts = new QTreeWidgetItem( trItemLocal );
	trItemLocalDrafts->setText( 0, QObject::tr("Черновики") );

	QIcon itemIcon(":/mainWnd/img/picSMSDrafts.png");
	trItemLocalInbox->setIcon(0, itemIcon);
	}}

	{{
	trItemLocalTrash = new QTreeWidgetItem( trItemLocal );
	trItemLocalTrash->setText( 0, QObject::tr("Удалённые") );

	QIcon itemIcon(":/mainWnd/img/picSMSTrash.png");
	trItemLocalTrash->setIcon(0, itemIcon);
	}}


	//--
	{{
	trItemSIM = new QTreeWidgetItem( mts_managerInstance->getLeftTree());
	trItemSIM->setText( 0, QObject::tr("SIM/USIM") );
	trItemSIM->setExpanded( true );

	QIcon itemIcon(":/mainWnd/img/picSMSSIM-grey.png");
	itemIcon.addPixmap(QPixmap(":/mainWnd/img/picSMSSIM.png"), QIcon::Active, QIcon::On);
	trItemSIM->setIcon(0, itemIcon);
	}}

	{{
	trItemSIMInbox = new QTreeWidgetItem( trItemSIM );
	trItemSIMInbox->setText( 0, QObject::tr("Входящие") );

	QIcon itemIcon(":/mainWnd/img/picSMSInbox.png");
	trItemSIMInbox->setIcon(0, itemIcon);
	}}

	{{
	trItemSIMOutbox = new QTreeWidgetItem( trItemSIM );
	trItemSIMOutbox->setText( 0, QObject::tr("Исходящие") );

	QIcon itemIcon(":/mainWnd/img/picSMSOutbox.png");
	trItemSIMOutbox->setIcon(0, itemIcon);
	}}

	{{
	trItemSIMDrafts = new QTreeWidgetItem( trItemSIM );
	trItemSIMDrafts->setText( 0, QObject::tr("Черновики") );

	QIcon itemIcon(":/mainWnd/img/picSMSDrafts.png");
	trItemSIMDrafts->setIcon(0, itemIcon);
	}}

	{{
	trItemSIMTrash = new QTreeWidgetItem( trItemSIM );
	trItemSIMTrash->setText( 0, QObject::tr("Удалённые") );

	QIcon itemIcon(":/mainWnd/img/picSMSTrash.png");
	trItemSIMTrash->setIcon(0, itemIcon);
	}}

	// mts_managerInstance->getLeftTree()->expandItem(trItemLocal);
}

void QSMSControl::OnItemExpanded(QTreeWidgetItem *item)
{
	QTreeWidget *leftTree = mts_managerInstance->getLeftTree();
	if (item == trItemLocal)
	{
		leftTree->collapseItem(trItemSIM);
		leftTree->expandItem(trItemLocal);
	}
	if (item == trItemSIM)
	{
		leftTree->collapseItem(trItemLocal);
		leftTree->expandItem(trItemSIM);
	}

}
